define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'assistant/assistant/index' + location.search,
                    // add_url: 'assistant/index/add',
                    edit_url: 'assistant/assistant/edit',
                    /*del_url: 'assistant/index/del',*/
                    multi_url: 'assistant/assistant/multi',
                    import_url: 'assistant/assistant/import',
                    table: 'assistant',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        /*{field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},*/
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'review_status', title: __('Review_status'), searchList: {"0":__('Review_status 0'),"1":__('Review_status 1'),"2":__('Review_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'assistant_price', title: '单价(元)', operate: "BETWEEN"},
                        {field: 'time_unit', title: '时间(分钟)', operate: "BETWEEN"},
                        {field: 'show_order_num', title: '显示订单数', operate: "BETWEEN"},
                        {field: 'order_num', title: '实际订单数', operate: false},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        //{field: 'store_id', title: __('Store_id')},
                        //{field: 'employee_id', title: __('Employee_id')},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'gender', title: __('Gender'), searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.normal},
                        {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'birthday', title: __('Birthday'), operate: 'LIKE'},
                        {field: 'level_name', title: __('Level'),operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'review_name', title: __('Review'),operate: false},
                        {field: 'reason', title: __('Reason'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'recommend', title: __('Recommend'), searchList: {"0":__('Recommend 0'),"1":__('Recommend 1')}, formatter: Table.api.formatter.toggle},
                        {field: 'order_switch', title: __('Order_switch'), searchList: {"0":__('Order_switch 0'),"1":__('Order_switch 1')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
